import React from 'react'

import {  Layout} from 'antd';  
import HomeHead from './components/HomeHead';
import HoemSider from './components/HomeSider';
import HomeContent from './components/HomeContent';

import { getUserInfoApi } from '../../apis/userApi';

import { eventBus } from '../../utils/eventBus';

export default function Home() {
  
  React.useEffect(()=>{
      eventBus.emit('refreshRoutes')

  },[])



  const countRef=React.useRef(0)
  console.log("countRef",countRef)
  const token = localStorage.token;
  const [isTruetoke,setisTruetoke]=React.useState(false)
if(!token){
  window.location.pathname = "/login";
  return null
}else{ 
  if (countRef.current===0) {
    countRef.current++
    getUserInfoApi()
    .then(res=>{
      setisTruetoke(true)
    })
    .catch(res=>{
      //返回假的
    })
  }

    if(!isTruetoke){
      return null
    }else{
      return (
    
        <Layout style={{minHeight:"100vh"}}>
       <HomeHead ></HomeHead>
       <Layout>
         <HoemSider>  
         </HoemSider>
         <HomeContent> 
         </HomeContent>
       </Layout>
     </Layout>
     )
    }
}

  
 
 
 
}

